import java.util.Scanner;

public class Text {
    //判定一个数字是否是素数
    public static void main1(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int i = 2;
        for(i = 2; i <= n / 2; i++) {
            if(n % i == 0) {
                System.out.println(n+"不是素数!");
                break;
            }
        }
        if(i > n / 2) {
            System.out.println(n+"是素数!");
        }
    }

    public static void main2(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int i = 2;
        for(i = 2; i <= Math.sqrt(n); i++) {
            if(n % i == 0) {
                System.out.println(n+"不是素数!");
                break;
            }
        }
        if(i > Math.sqrt(n)) {
            System.out.println(n+"是素数!");
        }
    }
    //打印 1 - 100 之间所有的素数
    public static void main3(String[] args) {
        for (int j = 1; j <= 100; j++) {
            int i = 2;
            for (i = 2; i <= Math.sqrt(j); i++) {
                if (j % i == 0) {
                    //.out.println(j + "不是素数!");
                    break;
                }
            }
            if (i > Math.sqrt(j)) {
                System.out.print(j + "是素数!" + " ");
            }
        }
    }
    //输出乘法口诀表
    public static void main4(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= i; j++) {
                System.out.print(i+"*"+j+"="+i*j+" ");
            }
            System.out.println();
        }
    }
    //求两个正整数的最大公约数
    public static void main5(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = a % b;
        while(c != 0) {
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(b);
    }
    // 求出0～999之间的所有“水仙花数”并输出。(“水仙花数”是指一个三位数，其各位数字的立方和确好等于该数
    //本身，如： 153＝1^3＋5^3＋3^3 ，则153是一个“水仙花数”。)
    public static void main6(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for(int i = 0; i < n; i++) {
            //判断i是几位数
            int count = 0;
            int tmp = i;
            while(tmp != 0){
                count++;
                tmp /= 10;
            }
            tmp = i;
            int sum = 0;
            while(tmp != 0) {
                sum += Math.pow(tmp % 10,count);
                tmp /= 10;
            }
            if(sum == i) {
                System.out.print(i + " ");
            }
        }
    }
    //返回参数二进制中 1 的个数
    public static void main7(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int count = 0;
        for(int i = 0; i < 32; i++) {
            if(((n >>> i) & 1) != 0) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main8(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int count = 0;
        while( n != 0) {
            if((n & 1) != 0) {
                count++;
            }
            n = n >>> 1;
        }
        System.out.println(count);
    }

    public static void main9(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int count = 0;
        while(n != 0) {
            n = n & (n-1);
            count++;
        }
        System.out.println(count);
    }
    //获取一个数二进制序列中所有的偶数位和奇数位，分别输出二进制序列。
    public static void main10(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        //偶数位
        for(int i = 31; i >= 1; i-=2) {
            System.out.print(((n>>i) & 1) + " ");
        }
        System.out.println();
        for(int i = 30; i >= 0; i -= 2) {
            System.out.print(((n>>i) & 1) + " ");
        }
    }
    //编写程序数一下 1到 100 的所有整数中出现多少个数字9
    public static void main11(String[] args) {
        int i = 1;
        int count = 0;
        for(i = 1; i <= 100; i++) {
            if(i % 10 == 9){
                count++;
            }
            if((i / 10 == 9)) {
                count++;
            }
        }
        System.out.println(count);
    }

    //打印*号
    public static void main31(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i == j || i + j == n-1) {
                    System.out.print("*");
                }else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }


    public static boolean isLeapYear(int year) {
        if((0 == year % 4 && 0 != year % 100) || 0 == year % 400) {
            return true;
        }else {
            return false;
        }
    }

    public static void main12(String[] args) {
        isLeapYear(2022);
    }


    public static int add(int x, int y) {
        return x + y;
    }
    //计算 1! + 2! + 3! + 4! + 5!
    public static void main33(String[] args) {
        int sum = 0;
        for (int i = 1; i <= 5; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(sum);
    }
    public static int facNum(int num) {
        int sum = 0;
        for(int j = 1; j <= num; j++) {
            sum += fac(j);
        }
        return sum;
    }
    public static int fac(int n) {
        int ret = 1;
        for(int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }
    public static void main13(String[] args) {
        System.out.println(facNum(5));
    }

    public static int add(int a, int b, int c) {
        return a+b+c;
    }
    public static double add(double a,int b) {
        return a+b;
    }
    public static double add(int b,double a) {
        return a+b;
    }
    public static double add(double a,double b) {
        return a+b;
    }

    public static void main14(String[] args) {
        int a = 10;
        int b = 20;
        int ret = add(a,b);
        System.out.println(ret);

        double d1 = 12.4;
        double d2 = 17.8;
        double ret2 = add(d1,d2);
        System.out.println(ret2);

        System.out.println(add(1,2,3));
    }
    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值 。
    public static void main17(String[] args) {
        int i = 0;
        double sum = 0;
        for (i = 1; i <= 100; ++i) {
            if (i % 2 == 0) {
                sum -= 1.0 / i;
            } else {
                sum += 1.0 / i;
            }
        }
        System.out.println(sum);
    }
        public static void main16(String[] args){
        double n = 1.0;
        double sum;  //用以保存最终结果
        double sum1 = 0.0;  //用以保存分母为奇数的分数和
        double sum2 = 0.0;  //用以保存分母为偶数的分数和
        while (n <= 100){
            if (n % 2 != 0){
                sum1 += (1 / n);  //求分母为奇数的分数和
            }
            else{
                sum2 += (1 / n);  //求分母为偶数的分数和
            }
            n++;
        }
        sum = sum1 - sum2;
        System.out.println("sum =" +sum);
    }
    //输出一个整数的每一位，如：123的每一位是3，2，1
    public static void main18(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int count= 0 ;
        int tmp = n;
        while(tmp != 0) {
            count++;
            tmp /= 10;
        }
        while(count != 0) {
            System.out.print(n % 10 +" ");
            n /= 10;
            count--;
        }
    }
    //编写代码模拟三次密码输入的场景。 最多能输入三次密码，密码正确，提示“登录成功”,密码错误，
    // 可以重新输 入，最多输入三次。三次均错，则提示退出程序
    public static void main19(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("请输入密码:");
        for(int i = 1; i <= 3; ++i ) {
            String passwd = input.nextLine();
            if (passwd.equals("123456")) {
                System.out.println("登录成功");
                break;
            }else {
                System.out.print("密码错误，请重新输入:");
            }
            if(i == 3) {
                System.out.println("退出程序");
            }

        }
    }

    // 创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
    // 要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算
    public static int max2(int a, int b) {
        if(a>b) {
            return a;
        }else {
            return b;
        }
    }
    public static int max3(int a, int b, int c) {
        if(max2(a,b)>c) {
            return max2(a,b);
        }else {
            return c;
        }
    }
    public static void main20(String[] args) {
        System.out.println(max2(4,7));
        System.out.println(max3(6,7, 15));
    }
    //求斐波那契数列的第n项。(迭代实现)
    public static int fab(int n) {
        if(n <= 0){
            return 0;
        }
        if( n == 1) {
            return 1;
        }
        return fab(n-1)+fab(n-2);
    }
    public static void main21(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        System.out.println(fab(n));
    }
    //在同一个类中,分别定义求两个整数的方法 和 三个小数之和的方法。 并执行代码，求出结果
    public static int sum(int a, int b) {
        return a+b;
    }
    public static double sum(double a, double b ,double c) {
        return a+b+c;
    }
    public static void main22(String[] args) {
        System.out.println(sum(4,7));
        System.out.println(sum(2.3,3.5,4.5));
    }

    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
    public static int max(int a, int b) {
        if(a > b) {
            return a;
        }else {
            return b;
        }
    }
    public static double max(double a, double b, double c) {
        if(a > b) {
            if(a > c) {
                return a;
            }else {
                return c;
            }
        } else {
            if(b > c) {
                return b;
            }else {
                return c;
            }
        }
    }
    public static void main30(String[] args) {
        System.out.println(max(10,40));
        System.out.println(max(11.4,23.3,3));
    }
}

























